<?php

	//No direct access
	defined('_JEXEC') or die('Restricted access');

	jimport('joomla.application.component.controller');

	class OwnserviceControllerMember extends JController
	{

	/**
	 * Controller onstruct
	*/
	function __construct(){
		parent::__construct();
	}

	/**
	 * Method to get detail member
	 *
	 * @return void
	 * @since 1.0
	*/
	function detail() {
		
		global $mainframe;
		
		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25){
			$canView		= Ownservice::checkAccess('member', 'view', 'member', 'all');
			if (!$canView) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('default');

		// Display the view
		$view->display();
	}

	/**
	 * Method to get form  edit member
	 *
	 * @return void
	 * @since 1.0
	 */
	function edit(){

		global $mainframe;
		// Check for request forgeries
		JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25) {
			$canEdit	= Ownservice::checkAccess('member', 'edit', 'member', 'all');
			if (!$canEdit ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('form');

		// Display the view
		$view->display();

	}

	/**
	* Method to add an member
	*
	* @access	public
	* @since	1.0
	*/
	function add() {

		global $mainframe;

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25) {
			$canAdd		= Ownservice::checkAccess('member', 'add', 'member', 'all');
			if (!$canAdd) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('form');

		// Display the view
		$view->display();
	}

	/**
	 * Logic to save member
	 *
	 * @access public
	 * @return void
	 * @since 1.0
	 */
	function save() {

		// Check for request forgeries
		JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );

		global $mainframe;

		//Initialise variables
		$db		= & JFactory::getDBO();
		$acl	= & JFactory::getACL();
		$me		= & JFactory::getUser();
		$ownuser= & Ownservice::getUser();
		$app	= & JFactory::getApplication();

		// Create a new JUser object
		$user = new JUser(JRequest::getVar( 'user_id', 0, 'post', 'int' ));

		$isNew 	= ($user->get('id') < 1);

		// Get vars 
		$post = JRequest::get('post');
		
		// Get/Create the model
		$model = & $this->getModel('Member');

		//check imember allready exists ?
		if( ($model->checkMember(trim($post['id_number']))) && ($isNew) )
		{
			$mainframe->enqueueMessage(JText::_('OWNSERVICE_THIS_ELECTRONIC_NO_ALREADY_EXISTS'), 'error');
			return $this->execute('edit');
		}
		
		//set full name
		$post['name']		= JRequest::getVar('firstname', '', 'post', 'string').' '.strtoupper(JRequest::getVar('lastname', '', 'post', 'string'));
		
		//set Username
		if($isNew) {
			$post['username']	= OwnserviceHelper::usernameFormat($post['firstname'], $post['lastname'], $post['birthday']);
		}

		//check username already exists?
		if( ($model->checkUsername(trim($post['username']))) && ($isNew) )
		{
			$chars = array('A'=>'A', 'B'=>'B','C'=>'C','D'=>'D','E'=>'E','F'=>'F','G'=>'G','H'=>'H','I'=>'I','J'=>'J','K'=>'K','L'=>'L','M'=>'M','N'=>'N','O'=>'O','P'=>'P','Q'=>'Q','R'=>'R','S'=>'S','T'=>'T','U'=>'U','V'=>'V','W'=>'W','X'=>'X','Y'=>'Y','Z'=>'Z');

			foreach($chars as $char)
			{
				if(!$model->checkUsername(trim($post['username']).$char))
				{
					$post['username'] = trim($post['username']).$char;
					break;
				}
			}
		}

		if(!$isNew) {
			$post['password']	= JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
			$post['password2']	= JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
		} else {
			$post['password']	= '123456';
			$post['password2']	= $post['password'];
		}
		
		$post['gid']	= isset($post['gid'])?$post['gid']: 18;

		$id = 0;
	
		if(!$isNew){
			$id			= JRequest::getVar( 'id', 0, 'post', 'int');
			$post['id'] = JRequest::getVar( 'user_id', 0, 'post', 'int');
		}

		if($post['email'] == '') {
			$post['email'] = $post['username'].'@gmail.com';
		}

		if (!$user->bind($post)) {
			$mainframe->enqueueMessage(JText::_('OWNSERVICE_ERROR_SAVE_USER'), 'message');
			$mainframe->enqueueMessage($user->getError(), 'error');
			return $this->execute('edit');
		}

		/*
	 	 * Lets save the JUser object
	 	 */
		if (!$user->save()) {
			$mainframe->enqueueMessage(JText::_('OWNSERVICE_ERROR_SAVE_USER'), 'message');
			$mainframe->enqueueMessage($user->getError(), 'error');
			return $this->execute('edit');
		}

		//delete own data of user all
		if($isNew) {
			//own users
			$query = 'DELETE * FROM #__ownservice_users WHERE user_id='.$user->get('id', 0);
			$db->setQuery($query);
			$db->query();

			//own accounts
			$query = 'DELETE * FROM #__ownservice_accounts WHERE user_id='.$user->get('id', 0);
			$db->setQuery($query);
			$db->query();

			//own files
			$query = 'DELETE * FROM #__ownservice_files WHERE userid='.$user->get('id', 0);
			$db->setQuery($query);
			$db->query();

			//own transactions
			$query = 'DELETE * FROM #__ownservice_transactions WHERE user_id='.$user->get('id', 0);
			$db->setQuery($query);
			$db->query();
		}

		// Set data to save
		$post['id']					= $id;
		$post['user_id']			= $user->get('id');
		$post['group_id']			= 1;
		$post['lastname']			= strtoupper($post['lastname']); 
		/*
		 * lets save the Ownservice user object
		*/
		if(!$model->store($post)){
			$mainframe->enqueueMessage(JText::_('OWNSERVICE_ERROR_SAVE_USER'), 'message');
			$mainframe->enqueueMessage($user->getError(), 'error');
			return $this->execute('edit');
		}

		// Manage Files

		$path		= OwnserviceHelper::getParams('path', 'images/stories/ownservices'); 
		$dir		= JPATH_SITE.DS.$path.DS.$model->get('user_id').DS;

		if($isNew){
			if($dh = opendir($dir)){
				while(($file = readdir($dh))!== false){
					if(file_exists($dir.$file)){ 
						@unlink($dir.$file);
					}
				}
					closedir($dh);
			}

			//$query = 'DELETE FROM #__ownservice_files WHERE userid='.$model->get('user_id');
			//$db->setQuery($query);
			//$db->query();
		}

		$file 	= JRequest::getVar( 'Filedata', '', 'files', 'array' );

		// Set FTP credentials, if given
		jimport('joomla.client.helper');
		JClientHelper::setCredentialsFromRequest('ftp');

		// Make the filename safe
		jimport('joomla.filesystem.file');

		for($i=0,$n=count($file['name']); $i<$n; $i++) {

			if(empty($file['name'][$i])) {
				break;
			}
			
			$file['name'][$i]	= JFile::makeSafe($file['name'][$i]);

			//get the extension to record it in the DB
			$ext					= strtolower(JFile::getExt($file['name'][$i]));

			if (isset($file['name'])) {

				$filepath = JPath::clean(JPATH_SITE.DS.$path.DS.$model->get('user_id').DS.strtolower($file['name'][$i]));

				if (!OwnserviceHelper::canUpload( $file, $i, $err )) {
					if ($format == 'json') {
						jimport('joomla.error.log');
						$log = &JLog::getInstance('upload.error.php');
						$log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err));
						header('HTTP/1.0 415 Unsupported Media Type');
						jexit('Error. Unsupported Media Type!');
					} else {
						JError::raiseNotice(100, strtolower($file['name'][$i]).' '.JText::_($err));
						break;
					}
				}

				if (JFile::exists($filepath)) {
					if ($format == 'json') {
						jimport('joomla.error.log');
						$log = &JLog::getInstance('upload.error.php');
						$log->addEntry(array('comment' => 'File already exists: '.$filepath));
						header('HTTP/1.0 409 Conflict');
						jexit('Error. File already exists');
					} else {
						JError::raiseNotice(100, strtolower($file['name'][$i]).' '.JText::_('Error. File already exists'));
						break;
					}
				}

				if (!JFile::upload($file['tmp_name'][$i], $filepath)) {
					if ($format == 'json') {
						jimport('joomla.error.log');
						$log = &JLog::getInstance('upload.error.php');
						$log->addEntry(array('comment' => 'Cannot upload: '.$filepath));
						header('HTTP/1.0 400 Bad Request');
						jexit('Error. Unable to upload file');
					} else {
						JError::raiseWarning(100, strtolower($file['name'][$i]).' '.JText::_('Error. Unable to upload file'));
						break;
					}
				} else {
					if ($format == 'json') {
						jimport('joomla.error.log');
						$log = &JLog::getInstance();
						$log->addEntry(array('comment' => $folder));
						jexit('Upload complete');
					} else {
						$mainframe->enqueueMessage(strtolower($file['name'][$i]).' '.JText::_('Upload complete'));
					}
				}

				// insert only the new records
				$createdate = & JFactory::getDate();
				$query = 'INSERT INTO #__ownservice_files (`userid`, `filename`, `ext`, `uploaded`, `uploaded_by`) '
					.' VALUES('.$model->get('user_id').','.$db->Quote(strtolower($file['name'][$i])).','.$db->Quote($ext).','.$db->Quote($createdate).','.$me->get('id').')';
				
				$db->setQuery($query);
				$db->query();
			}

		}

		$delete = JRequest::getVar( 'delete', array(0), 'post', 'array' );

		if(count( $delete ) > 0) {
			foreach($delete as $del) {
				if( $del > 0 ) {
					$query = 'SELECT * FROM #__ownservice_files WHERE id='.$del;
					$db->setQuery($query);
					$data = $db->loadObject();

					$query = 'DELETE FROM #__ownservice_files where id='.$del;
					$db->setQuery($query);
					if(!$db->query()) {
						JError::raiseNotice(100, JText::_('Unable to delete:').$data->filename);
						break;
					}

					$path	  = OwnserviceHelper::getParams('path', 'images/stories/ownservices'); 
					$origpath = JPath::clean(JPATH_SITE.DS.$path.DS.$data->userid.DS.$data->filename);
					// delete the original image from file manager
					if (!JFile::delete($origpath)) {
						JError::raiseNotice(100, JText::_('Unable to delete:').$data->filename);
					}

					$mainframe->enqueueMessage(JText::_('succesfully removed:').$data->filename);
				}
			}
		}

		if($id > 0){
			$msg = JText::sprintf( 'SUCCESSFULLY SAVED CHANGES TO USER', $user->get('name') );
		} else {
			$msg = JText::sprintf( 'SUCCESSFULLY SAVED USER', $user->get('name') );
		}

		$link = JRoute::_('index.php?option=com_ownservice&view=member&id='.$model->get('id'));

		$this->setRedirect($link, $msg);
	}

	/**
	 * Removes the record(s) member from the database
	 */
	function delete()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		$me = & JFactory::getUser();
		$app = & JFactory::getApplication();

		if($me->gid < 25){
			$canDelete = Ownservice::checkAccess('member', 'delete', 'member', 'all');
			if (!$canDelete) {
				JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
			}
		}

		$db 	=& JFactory::getDBO();
		$acl	=& JFactory::getACL();
		$id 	=JRequest::getVar( 'id', 0, 'post', 'int' );

		if ($id <= 0) {
			JError::raiseError(500, JText::_('OWNSERVICE_SELECT_USER_TO_DELETE', true ) );
		}

		//$model	= $this->getModel('Member');
		//$row	= $model->getUser($id);

		$query = 'SELECT * FROM #__ownservice_users WHERE id='.$id;
		$db->setQuery($query);
		$row=$db->loadObject();

		$user =& JUser::getInstance((int)$row->user_id);
		
		//delete user
		if($user->delete()) {

			//own users
			$query = 'DELETE FROM #__ownservice_users WHERE user_id='.$row->user_id;
			$db->setQuery($query);
			if($db->query()) {
				//own accounts
				$query = 'DELETE FROM #__ownservice_accounts WHERE user_id='.$row->user_id;
				$db->setQuery($query);
				$db->query();

				//own files
				$query = 'DELETE FROM #__ownservice_files WHERE userid='.$row->user_id;
				$db->setQuery($query);
				if($db->query()) {
					$path		= OwnserviceHelper::getParams('path', 'images/stories/ownservices'); 
					$dir		= JPATH_SITE.DS.$path.DS.$row->user_id;
					foreach(glob($dir.DS.'*.*') as $file){
						unlink($file);
					}
				}

				//own transactions
				//$query = 'DELETE * FROM #__ownservice_transactions WHERE user_id='.$id;
				//$db->setQuery($query);
				//$db->query();
			}

			$msg = JText::_( 'USER DELETED' );
		} else {
			$msg = JText::_('OWNSERVICE_OPERATION_FAILED');
		}

		//$user->block = 1;
		//$user->save();

		/*
		 * delete the ownservices user 
		*/
		//$model->delete($id);

		$link = JRoute::_('index.php?option=com_ownservice&view=members');

		$this->setRedirect( $link, $msg);
	}

	/**
	 * logic for cancel an action
	 *
	 * @access public
	 * @return void
	 * @since 1.0
	 */
	function cancel()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		$app = & JFactory::getApplication();

		$link = JRoute::_('index.php?option=com_ownservice&view=members');

		$this->setRedirect( $link );
	}

	/**
	 * Download logic
	 *
	 * @access public
	 * @since 1.0
	 */
	function download()
	{
		global $mainframe;
		
		jimport('joomla.filesystem.file');

		$id 		= JRequest::getInt( 'id', 0 );
		$db			= &JFactory::getDBO();
		$user		= & JFactory::getUser();

		if($user->gid < 25){
			$canDownload = Ownservice::checkAccess('member', 'download', 'member', 'all');
			if (!$canDownload) {
				JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
			}
		}

		$query  = 'SELECT * FROM #__ownservice_files WHERE id='.$id;

		$db->setQuery($query);
		$data = $db->loadObject();

		$basePath = JPATH_SITE.DS.OwnserviceHelper::getParams('path', 'images/stories/ownservices');

		$abspath = str_replace(DS, '/', JPath::clean($basePath.DS.$data->userid.DS.$data->filename));

		if (!JFile::exists($abspath)) {
			$msg 	= JText::_( 'OWNSERVICE_REQUESTED_FILE_DOES_NOT_EXIST_ANYMORE' );
			$link 	= 'index.php';
			$this->setRedirect($link, $msg);
			return;
		}
		
		//get filesize and extension
		$size 	= filesize($abspath);
		$ext 	= $data->ext;
	
		// required for IE, otherwise Content-disposition is ignored
		if(ini_get('zlib.output_compression')) {
			ini_set('zlib.output_compression', 'Off');
		}

		switch( $ext )
		{
			case "pdf":
				$ctype = "application/pdf";
				break;
			case "exe":
				$ctype="application/octet-stream";
				break;
			case "rar":
			case "zip":
				$ctype = "application/zip";
				break;
			case "txt":
				$ctype = "text/plain";
				break;
			case "doc":
				$ctype = "application/msword";
				break;
			case "xls":
				$ctype = "application/vnd.ms-excel";
				break;
			case "ppt":
				$ctype = "application/vnd.ms-powerpoint";
				break;
			case "gif":
				$ctype = "image/gif";
				break;
			case "png":
				$ctype = "image/png";
				break;
			case "jpeg":
			case "jpg":
				$ctype = "image/jpg";
				break;
			case "mp3":
				$ctype = "audio/mpeg";
				break;
			default:
				$ctype = "application/force-download";
		}
		
		/*		
		JResponse::setHeader('Pragma', 'public');
		JResponse::setHeader('Expires', 0);
		JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
		JResponse::setHeader('Cache-Control', 'private', false);
		JResponse::setHeader('Content-Type', $ctype);
		JResponse::setHeader('Content-Disposition', 'attachment; filename="'.$data.'";');
		JResponse::setHeader('Content-Transfer-Encoding', 'binary');
		JResponse::setHeader('Content-Length', $size);
		*/
		header("Pragma: public"); // required
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: private",false); // required for certain browsers
		header("Content-Type: $ctype");
		//quotes to allow spaces in filenames
		header("Content-Disposition: attachment; filename=\"".$data->filename."\";" );
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: ".$size);

		readfile($abspath);
		$mainframe->close();
	}

	/*accounts*/

	/**
	 * Method to get receiver accounts
	 *
	 * @return void
	 * @since 1.0
	 */
	function account() {

		global $mainframe;

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25){
			$canView		= Ownservice::checkAccess('account', 'view', 'account', 'all');
			if (!$canView) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('account');

		// Display the view
		$view->display();
	}
	
	/**
	 * Method to get transfer history of member
	 * 
	 * @return void
	 * @since 1.0
	 */
	 function transfer()
	 {
	 	global $mainframe;

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25){
			$canView		= Ownservice::checkAccess('transaction', 'view', 'transaction', 'all');
			if (!$canView) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}
		
		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('transfer');

		// Display the view
		$view->display();
	 }

	/**
	 * Method to get detail receiver of member
	 *
	 * @return void
	 * @since 1.0
	*/
	function acdetail() {

		global $mainframe;

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25){
			$canView		= Ownservice::checkAccess('account', 'view', 'account', 'all');
			if (!$canView) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('detailaccount');

		// Display the view
		$view->display();
	}

	/**
	* Method to add account an member
	*
	* @access	public
	* @since	1.0
	*/
	function acadd() {

		global $mainframe; 
	
		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25) {
			$canAdd		= Ownservice::checkAccess('account', 'add', 'account', 'all');
			if (!$canAdd) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}
		
		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('formaccount');

		// Display the view
		$view->display();
	}

	/**
	 * Method to get form  edit account of member
	 *
	 * @return void
	 * @since 1.0
	 */
	function acedit(){

		global $mainframe;
		// Check for request forgeries
		JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		if($user->gid < 25) {
			$canEdit	= Ownservice::checkAccess('account', 'edit', 'account', 'all');
			if (!$canEdit ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('member', 'html');

		// Get/Create the model
		$model = & $this->getModel('Member');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('formaccount');

		// Display the view
		$view->display();

	}

	/**
	 * Logic to save receiver account
	 * 
	 * @access public
	 * @return void
	*/
	function acsave(){

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		$app = & JFactory::getApplication();

		// Get vars
		$post = JRequest::get( 'post' );

		$model = $this->getModel('Account');

		$type = '';

		if($model->store($post)){
			$msg = JText::_('OWNSERVICE_ACCOUNT_SAVED');
		} else {
			$type = 'error';
			$msg = JText::_('OWNSERVICE_ERROR_SAVING_ACCOUNT');
		}

		$link = JRoute::_('index.php?option=com_ownservice&controller=member&task=account&id='.$post['mid']);
		
		$this->setRedirect($link, $msg, $type);
	}

	
	/**
	 * Logic to delete account of member
	 *
	 * @access public
	 * @return void
	 * @since 1.0
	*/
	function acdel(){

		global $mainframe;

		// Check for request forgeries
		JRequest::checkToken('request') or jexit( 'Invalid Token' );

		$user	= & JFactory::getUser();
		$app	= & JFactory::getApplication();

		if( $user->gid <25 ) {
			$canDelete		= Ownservice::checkAccess('account', 'delete', 'account', 'all');
			if ( !$canDelete ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//get var
		$post = JRequest::get('Post');
		$id = JRequest::getVar('id',0, 'post', 'int');

		$model=& $this->getModel('Accounts');
		if ($model->delete($id)) {
			$msg = JText::_('OWNSERVICE_ACCOUNT_DELETED');
		} else {
			$msg = JText::_( 'OWNSERVICE_ACCOUNT_FAILED' );
		}

		$link = JRoute::_('index.php?option=com_ownservice&controller=member&task=account&mid='.$post['mid']);

		$this->setRedirect( $link, $msg );
	}

	/**
	 * Method to import php excel data
	 *
	 * @since 1.5
	*/
	function importuser()
	{
		global $mainframe;

		$db			= & JFactory::getDBO();
		$me			= & JFactory::getUser();
		$date		= & JFactory::getDate();

		//get var
		$files	= JRequest::get( 'files', JREQUEST_ALLOWRAW );

		/*$rows = $this->parseExcelMember($files);
		echo '<pre>';print_r($rows); echo '</pre>';
		exit();*/

		if($rows = $this->parseExcelMember($files))
		{
			if(count($rows) >= 1)
			{

				foreach($rows as $row)
				{
					if($row->username)
					{
						$post = array();

						// select member data
						$query = 'SELECT * FROM #__ownservice_users '
								.' WHERE id='.$row->id
								;
						$db->setQuery($query);
						$data = $db->loadObject();

						if(is_object($data))
						{
							if($data->id != (int)$row->id)
							{
								$row->id		= 0;
								$row->user_id	= 0;
							}
							else
							{
								$row->user_id = $data->user_id;
							}
						}

						// Create a new JUser object
						$user = new JUser($row->user_id);

						$isNew 	= ($user->get('id') < 1);

						$post['name']		= $row->firstname.' '.$row->lastname;
						$post['username']	= $row->username;
						$post['email']		= $row->email;

						if(!$isNew) {
							$post['id']			= $user->get('id');
							$post['password']	= '';
							$post['password2']	= '';
						} else {
							$post['id']			= 0;
							$post['password']	= '123456';
							$post['password2']	= $post['password'];
						}

						$post['gid']	= $user->get('gid')?$user->get('gid'): 18;

						// Bind the post array to the user object
						if (!$user->bind( $post, 'usertype' )) {
							JError::raiseError( 500, $user->getError().' '.dir(__LINE__));
						}

						// If there was an error with registration, set the message and display form
						if ( !$user->save() )
						{
							JError::raiseWarning('', $post['name'].' '.JText::_( $user->getError()));
							return $this->execute('');
						}

						$row->user_id = $user->get('id');

						// select branch id
						$query = ' SELECT id FROM #__ownservice_branches WHERE code='.$db->Quote($row->branch_code);
						$db->setQuery($query);
						$branchid = $db->loadResult();

						if($branchid) {
							$row->branch_id = $branchid;
						}

						unset($row->username);
						unset($row->email);
						unset($row->occupation);
						unset($row->occupation);
						unset($row->branch_code);
						if(!$row->id)
						{
							$row->group_id	= 1;
							if(!$db->insertObject('#__ownservice_users', $row,'id')) {
								$mainframe->enqueueMessage('Error import member '.$row->firstname.' '.$row->lastname.' '.dir(__LINE__), 'error');
								return $this->execute('');
							}
						}
						else
						{
							if(!$db->updateObject('#__ownservice_users', $row, 'id')) {
								$mainframe->enqueueMessage('Error update member '.$row->firstname.' '.$row->lastname.' '.dir(__LINE__),'error');
								return $this->execute('');
							}
						}

						//member accounts
						$accounts = $row->accounts;
						if(count($accounts) >=1 )
						{
							foreach($accounts as $account)
							{
								if($account->account_no) 
								{
									$query = ' SELECT id FROM '
											.' #__ownservice_accounts '
											.' WHERE account_no='.$db->Quote($account->account_no)
											.' AND user_id='.$row->user_id;
									$db->setQuery($query);
									$accid = $db->loadResult();
									
									$account->id			= $accid;
									$account->user_id		= $row->user_id;
									$account->account_name	= $account->firstname.' '.$account->lastname;

									//unset($account->dob);
									unset($account->firstname);
									unset($account->lastname);
									//unset($account->bank_city);

									if(!$accid)
									{
										$account->created		= $date->toMySQL();
										$account->created_by	= $me->get('id');
										//insert account
										$db->insertObject('#__ownservice_accounts', $account,'id');
									}
									else
									{
										$account->modified		= $date->toMySQL();
										$account->modified_by	= $me->get('id');
										//update account
										$db->updateObject('#__ownservice_accounts', $account, 'id');
									}
								}
							}
						}
					}//end if check username
				}
			}
		}

		$mainframe->redirect(JRoute::_('index.php?option=com_ownservice&view=members'), JText::_('Import member success'));
	}

	function parseExcelMember($files)
	{
		global $mainframe;

		require_once(JPATH_COMPONENT_SITE.DS.'classes'.DS.'PHPExcel'.DS.'IOFactory.php');
		require_once(JPATH_COMPONENT_SITE.DS.'classes'.DS.'PHPExcel.php');

		//set vars
		$uploadfile = $files['file']['tmp_name'];

		 //load the file using the library
        $objPHPExcel = PHPExcel_IOFactory::load($uploadfile);

		//get the active sheet
        $worksheet = $objPHPExcel->getActiveSheet();

		//Work out if 1900 (Win) or 1904 (Mac) calendar
        //$calendar = PHPExcel_Shared_Date::getExcelCalendar();

        //Will only return a filetype if CSV
        $filetype = $objPHPExcel->fileType;

		//Get the last used row in the file
        $last_row = $worksheet->getHighestRow();

		//Get the last used column in the file
        $last_col = $worksheet->getHighestColumn();

		// Get collection of column dimensions
		//$currentColumnDimensions = $worksheet->getColumnDimensions();

		//Get the num column
		$numcol	= PHPExcel_Cell::columnIndexFromString($last_col)-1;

		$member = array();

		//Loop thru the rows in the excel file
        for ($i = 3 ; $i <= $last_row ; $i++ ) 
		{
			if($worksheet->getCellByColumnAndRow(1,$i)->getValue()) 
			{
				$row	= new stdClass();
				$acc	= array();
				$rowacc = new stdClass();

				for($c=0; $c <= $numcol; $c++) 
				{
					//column index
					$indexcol = $c;

					// data user
					if($indexcol >= 0 && $indexcol <= 18) 
					{
						
						// ID
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ID') {
							$row->id = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						// USERNAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'USERNAME') {
							$row->username = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//FIRSTNAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'FIRST NAME') {
							$row->firstname = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//LASTNAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'LAST NAME') {
							$row->lastname = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//NICKNAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'NICK NAME') {
							$row->nickname = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//BIRTHDAY
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'DOB') {
							$row->birthday = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//PHONE NO
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'PHONE NO.') {
							$row->phone_no = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//EMAIL
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'EMAIL') {
							$row->email	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//ADDRESS
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ADDRESS') {
							$row->address	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//CITY
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'SUBURB') {
							$row->city	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//STATE
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'STATE') {
							$row->state	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//POSTCODE
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'POSTCODE') {
							$row->postcode	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//COUNTRY
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'COUNTRY') {
							$row->country	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//ID TYPE
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ID TYPE') {
							$row->id_type	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//ID NO.
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ID NO.') {
							$row->id_number	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//ISSUER
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ISSUER') {
							$row->issuer	= $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//EXPIRE DATE
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'EXPIRE DATE') {
							$row->expire_date = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//CURRENCY
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'CURRENCY') {
							$row->currency = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//BRANCH REF.
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'BRANCH REF.') {
							$row->branch_code = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

					} //end user
					else
					{
						// data accounts

						//FIRSTNAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'FIRST NAME') {
							$rowacc->firstname = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//LASTNAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'LAST NAME') {
							$rowacc->lastname = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//PHONE NO.
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'PHONE NO.') {
							$rowacc->phone_no = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//EMAIL
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'EMAIL') {
							$rowacc->email = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//ADDRESS
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ADDRESS') {
							$rowacc->address = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//SUBURB
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'SUBURB') {
							$rowacc->city = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//STATE
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'STATE') {
							$rowacc->state = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//POSTCODE
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'POSTCODE') {
							$rowacc->postcode = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//COUNTRY
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'COUNTRY') {
							$rowacc->country = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//ACCOUNT NO.
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'ACCOUNT NO.') {
							$rowacc->account_no = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//BANK NAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'BANK NAME') {
							$rowacc->bank_name = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//BRANCH NAME
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'BRANCH NAME') {
							$rowacc->branch_name = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();
						}

						//BRANCH CITY
						if(strtoupper($worksheet->getCellByColumnAndRow($indexcol,2)->getValue()) == 'BRANCH CITY') {
							$rowacc->branch_city = $worksheet->getCellByColumnAndRow($indexcol,$i)->getValue();

							if($rowacc->account_no != ''){
								$acc[] = $rowacc;
							}
							$rowacc  = new stdClass();
						}
					}
				}

				$row->accounts =$acc;
				if($row->username) {
					$member[] = $row;
				}
			}//end check username
		}

		return $member;
	}

	function export() {

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canExport = Ownservice::checkAccess('member', 'export', 'member', 'all');
			if ( !$canExport ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//Get data from the model
		$model		= $this->getModel('Members');
		$rows		= $model->getExportMembers();
		$countAcc	= $model->getMaxAccount();

		require_once(JPATH_COMPONENT_SITE.DS.'classes'.DS.'PHPExcel.php');

		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();
		
		// Set properties
		$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
							 ->setLastModifiedBy("Maarten Balliauw")
							 ->setTitle("Office 2007 XLSX Test Document")
							 ->setSubject("Office 2007 XLSX Test Document")
							 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
							 ->setKeywords("office 2007 openxml php")
							 ->setCategory("Test result file");

		//Set default font
		$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Arial');
		$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(8);

		// Set row height
		$objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(15);

		// Add some data
		/*$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Member details');
		*/
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A2', 'Username');
		/*	
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A2', 'ID')
            ->setCellValue('B2', 'Username')
			->setCellValue('C2', 'First Name')
			->setCellValue('D2', 'Last Name')
			->setCellValue('E2', 'Nick Name')
			->setCellValue('F2', 'DOB')
			->setCellValue('G2', 'Phone No.')
			->setCellValue('H2', 'Email')
			->setCellValue('I2', 'Address')
			->setCellValue('J2', 'Suburb')
			->setCellValue('K2', 'State')
			->setCellValue('L2', 'Postcode')
			->setCellValue('M2', 'Country')
			->setCellValue('N2', 'ID Type')
			->setCellValue('O2', 'ID No.')
			->setCellValue('P2', 'Issuer')
			->setCellValue('Q2', 'Expire Date')
			->setCellValue('R2', 'Currency')
			->setCellValue('S2', 'Branch Ref.');*/

		$c = 0;
		for($a=1; $a <= $countAcc; $a++)
		{
			$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValueByColumnAndRow($c+2, '1', 'Beneficiary Ref '.$a);

			$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValueByColumnAndRow($c+2, '2', 'First Name')
			->setCellValueByColumnAndRow($c+3, '2', 'Last Name')
			->setCellValueByColumnAndRow($c+4, '2', 'Phone No.')
			->setCellValueByColumnAndRow($c+5, '2', 'Email')
			->setCellValueByColumnAndRow($c+6, '2', 'Address')
			->setCellValueByColumnAndRow($c+7, '2', 'Suburb')
			->setCellValueByColumnAndRow($c+8, '2', 'State')
			->setCellValueByColumnAndRow($c+9, '2', 'Postcode')
			->setCellValueByColumnAndRow($c+10, '2', 'Country')
			->setCellValueByColumnAndRow($c+11, '2', 'Account No.')
			->setCellValueByColumnAndRow($c+12, '2', 'Bank Name')
			->setCellValueByColumnAndRow($c+13, '2', 'Branch Name')
			->setCellValueByColumnAndRow($c+14, '2', 'Branch city');

			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($c+2, 1, $c+14, 1);

			// Set style on cell
			$objPHPExcel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($c+2).'1:'.PHPExcel_Cell::stringFromColumnIndex($c+14).'1')->applyFromArray(
				array(
					'alignment' => array(
					'horizontal' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
					'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
					)
				)
			);

			$c = $c+14;
		}
		
		/*if( count($rows) > 0 )
		{
			$i =  3;
			foreach($rows as $row)
			{
				$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i, $row->id)
					->setCellValue('B'.$i, $row->username)
					->setCellValue('C'.$i, $row->firstname)
					->setCellValue('D'.$i, $row->lastname)
					->setCellValue('E'.$i, $row->nickname)
					->setCellValue('F'.$i, $row->birthday)
					->setCellValue('H'.$i, $row->email)
					->setCellValue('I'.$i, $row->address)
					->setCellValue('J'.$i, $row->city)
					->setCellValue('K'.$i, $row->state)
					->setCellValue('M'.$i, $row->country)
					->setCellValue('N'.$i, $row->id_type)
					->setCellValue('P'.$i, $row->issuer)
					->setCellValue('Q'.$i, $row->expire_date)
					->setCellValue('R'.$i, $row->currency)
					->setCellValue('S'.$i, $row->branchcode);

				$objPHPExcel->getActiveSheet()->getCell('G'.$i)->setValueExplicit($row->phone_no, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('L'.$i)->setValueExplicit($row->postcode, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('O'.$i)->setValueExplicit($row->id_number, PHPExcel_Cell_DataType::TYPE_STRING);

				//accounts
				$c = 18;
				for($a=0, $n=count($row->accounts); $a < $n; $a++)
				{
					$accname = explode(' ', $row->accounts[$a]->account_name);
					$objPHPExcel->setActiveSheetIndex(0)
					->setCellValueByColumnAndRow($c+2, $i, trim($accname[0]))
					->setCellValueByColumnAndRow($c+3, $i, trim($accname[1]))
					->setCellValueByColumnAndRow($c+5, $i, $row->accounts[$a]->email)
					->setCellValueByColumnAndRow($c+6, $i, $row->accounts[$a]->address)
					->setCellValueByColumnAndRow($c+7, $i, $row->accounts[$a]->city)
					->setCellValueByColumnAndRow($c+8, $i, $row->accounts[$a]->state)
					->setCellValueByColumnAndRow($c+10, $i, $row->accounts[$a]->country)
					->setCellValueByColumnAndRow($c+12, $i, $row->accounts[$a]->bank_name)
					->setCellValueByColumnAndRow($c+13, $i, $row->accounts[$a]->branch_name)
					->setCellValueByColumnAndRow($c+14, $i, $row->accounts[$a]->branch_city);

					$objPHPExcel->getActiveSheet()->getCell(PHPExcel_Cell::stringFromColumnIndex($c+4).$i)->setValueExplicit($row->accounts[$a]->phone_no, PHPExcel_Cell_DataType::TYPE_STRING);
					$objPHPExcel->getActiveSheet()->getCell(PHPExcel_Cell::stringFromColumnIndex($c+9).$i)->setValueExplicit($row->accounts[$a]->postcode, PHPExcel_Cell_DataType::TYPE_STRING);
					$objPHPExcel->getActiveSheet()->getCell(PHPExcel_Cell::stringFromColumnIndex($c+11).$i)->setValueExplicit($row->accounts[$a]->account_no, PHPExcel_Cell_DataType::TYPE_STRING);

					$c = $c+14;
				}
				$i++;
			}
		}*/

		//$objPHPExcel->getActiveSheet()->mergeCells('A1:S1');

		// Freeze panes
		$objPHPExcel->getActiveSheet()->freezePane('A3');

		// Set style on cell
		/*$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->applyFromArray(
			array(
				'alignment' => array(
				'horizontal' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
				'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
				)
			)
		);*/

		// Rename sheet
		$objPHPExcel->getActiveSheet()->setTitle('EXPORT MEMBERS');


		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);

		// Redirect output to a client�s web browser (Excel2007)
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="'.date('d-m-Y').'EXPORT-MEMBERS.xlsx"');
		header('Cache-Control: max-age=0');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
		exit;

	}

	function getCurrency()
	{
		// Check for request forgeries
		JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
		
		$branch_id = JRequest::getVar('branch_id', 0, 'post', 'int');
		
		$model = $this->getModel('Member');
		
		$currencies	= $model->getCurrencies($branch_id);
		
		//build currency exchange list
		$lists['currency'] = OwnserviceHelper::buildcurrenciesselect($currencies, 'rate_id', '', true, 'class="inputbox" style="width:250px;"');
		
		echo $lists['currency'];
		
		exit();
	}
}
?>